// Upgrade NOTE: commented out 'float4 unity_LightmapST', a built-in variable
// Upgrade NOTE: commented out 'float4x4 _Object2World', a built-in variable
// Upgrade NOTE: commented out 'sampler2D unity_Lightmap', a built-in variable
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
// Upgrade NOTE: replaced 'glstate_matrix_mvp' with 'UNITY_MATRIX_MVP'
// Upgrade NOTE: replaced tex2D unity_Lightmap with UNITY_SAMPLE_TEX2D


Shader  "Custom/DiffuseClipPlaneTest" {

	Properties
	 {
 _MainTex ("Texture 1", 2D) = "white" {}
 _LightColour0 ("Light colour 0", Color) = (1,0.73,0.117,0)
 _LightColour1 ("Light colour 1", Color) = (0.05,0.275,0.275,0)
 _LightColour2 ("Light colour 2", Color) = (0,0,0,0)
 _LightColour3 ("Rim colour", Color) = (0,0,0,0)
 _LightTint ("Light Multiplier", Color) = (1,1,1,0)
 _AmbientColour1 ("Light Add", Color) = (0.5,0.5,0.5,0)
 _ShadowColour ("Shadow Tint", Color) = (0,0,0,0)
 _ShadowRamp ("ShadowBoost", Float) = 1
 _UseLightMap ("Debug Mode", Float) = 1
 _Plane0 ("_Plane0", Vector) = (0,1,0,1)
 _Plane1 ("_Plane1", Vector) = (0,1,0,1)
 _Plane2 ("_Plane2", Vector) = (0,1,0,1)
 _Plane3 ("_Plane3", Vector) = (0,1,0,1)
 _Plane4 ("_Plane4", Vector) = (0,1,0,1)
 _Plane5 ("_Plane5", Vector) = (0,1,0,1)
}

	

	SubShader
	{
	Pass
	
	 {
  Tags { "LIGHTMODE"="ForwardBase" "RenderType"="Opaque" }
  Blend SrcAlpha One
    LOD 100

	CGPROGRAM
	#pragma vertex vert
	#pragma fragment frag
	#include "UnityCG.cginc"

	struct VertexInput {
    fixed4 vertex : POSITION;
	fixed2 uv:TEXCOORD0;
    fixed2 xlv_TEXCOORD1 : TEXCOORD1;
    float3 xlv_TEXCOORD2 : TEXCOORD2;
    float3 xlv_TEXCOORD3 : TEXCOORD3;
    fixed4 tangent : TANGENT;
    fixed3 normal : NORMAL;
    fixed3 xlv_COLOR : COLOR;
	//VertexInput
	};


	struct VertexOutput {
	fixed4 pos : SV_POSITION;
	fixed2 uv:TEXCOORD0;
    fixed2 xlv_TEXCOORD1 : TEXCOORD1;
    float3 xlv_TEXCOORD2 : TEXCOORD2;
    float3 xlv_TEXCOORD3 : TEXCOORD3;
	//VertexOutput
	};

 
 // float4x4 _Object2World;
 // float4 unity_LightmapST;
 float4 _MainTex_ST;
 float4 _LightColour0;
 float4 _LightColour1;
 float4 _LightColour2;
 float4 _LightColour3;
 float4 _AmbientColour1;


	

 // sampler2D unity_Lightmap;
 sampler2D _MainTex;
 float _ShadowRamp;
 float4 _ShadowColour;
 float4 _LightTint;
 float _UseLightMap;
 float4 _Plane0;
 float4 _Plane1;
 float4 _Plane2;
 float4 _Plane3;
 float4 _Plane4;
 float4 _Plane5;




	VertexOutput vert (VertexInput v)
	{
	VertexOutput o;
	//o.pos = UnityObjectToClipPos (v.vertex);
	//o.uv = v.uv;
	
  float angle2Norm_1;
  float3 colourTo2_2;
  float3 darkSide3_3;
  float3 darkSide1_4;
  float3 colourTo_5;
  float3 colourFrom_6;
  float angleNorm_7;
  float3 flatWorldNormal_8;
  float4 tmpvar_9;
  tmpvar_9 = UnityObjectToClipPos(v.vertex);
  float2 tmpvar_10;
  tmpvar_10 = ((v.uv * _MainTex_ST.xy) + _MainTex_ST.zw);
  float2 tmpvar_11;
  tmpvar_11 = ((v.xlv_TEXCOORD1 * unity_LightmapST.xy) + unity_LightmapST.zw);
  float3 tmpvar_12;
  tmpvar_12 = mul(unity_ObjectToWorld , v.vertex).xyz;
  float4 tmpvar_13;
  tmpvar_13.w = 0.0;
  tmpvar_13.xyz = normalize(v.normal);
  float3 tmpvar_14;
  tmpvar_14 = normalize(mul(unity_ObjectToWorld , tmpvar_13).xyz);
  flatWorldNormal_8.xy = tmpvar_14.xy;
  flatWorldNormal_8.z = 0.0;
  float tmpvar_15;
  tmpvar_15 = sqrt(dot (flatWorldNormal_8, flatWorldNormal_8));
  if ((tmpvar_15 > 0.0001)) {
    flatWorldNormal_8 = normalize(flatWorldNormal_8);
  };
  float tmpvar_16;
  tmpvar_16 = clamp (-(flatWorldNormal_8).x, -1.0, 1.0);
  float tmpvar_17;
  tmpvar_17 = ((1.5708 - (
    sign(tmpvar_16)
   * 
    (1.5708 - (sqrt((1.0 - 
      abs(tmpvar_16)
    )) * (1.5708 + (
      abs(tmpvar_16)
     * 
      (-0.214602 + (abs(tmpvar_16) * (0.0865667 + (
        abs(tmpvar_16)
       * -0.0310296))))
    ))))
  )) / 1.5708);
  angleNorm_7 = tmpvar_17;
  colourFrom_6 = _LightColour0.xyz;
  colourTo_5 = _LightColour1.xyz;
  darkSide1_4 = _LightColour3.xyz;
  darkSide3_3 = _LightColour3.xyz;
  if ((_UseLightMap < 0.5)) {
    darkSide1_4 = fixed3(0.5, 0.5, 0.5);
    darkSide3_3 = fixed3(0.75, 0.75, 0.75);
  };
  if ((flatWorldNormal_8.x > 0.0)) {
    colourFrom_6 = darkSide1_4;
    angleNorm_7 = (2.0 - tmpvar_17);
  };
  if ((flatWorldNormal_8.y < 0.0)) {
    colourTo_5 = darkSide1_4;
  };
  float3 tmpvar_18;
  tmpvar_18 = lerp (colourFrom_6, colourTo_5, fixed3(angleNorm_7,angleNorm_7,angleNorm_7));
  colourTo2_2 = _LightColour2.xyz;
  float tmpvar_19;
  tmpvar_19 = clamp (-(tmpvar_14).z, -1.0, 1.0);
  float tmpvar_20;
  tmpvar_20 = (1.0 - ((1.5708 - 
    (sign(tmpvar_19) * (1.5708 - (sqrt(
      (1.0 - abs(tmpvar_19))
    ) * (1.5708 + 
      (abs(tmpvar_19) * (-0.214602 + (abs(tmpvar_19) * (0.0865667 + 
        (abs(tmpvar_19) * -0.0310296)
      ))))
    ))))
  ) / 1.5708));
  angle2Norm_1 = tmpvar_20;
  if ((-(tmpvar_14.z) < 0.0)) {
    colourTo2_2 = darkSide3_3;
  };
  if ((tmpvar_20 < 0.0)) {
    angle2Norm_1 = -(tmpvar_20);
  };
  o.pos = tmpvar_9;
  o.uv = tmpvar_10;
  o.xlv_TEXCOORD1 = tmpvar_11;
  o.xlv_TEXCOORD2 = (lerp (tmpvar_18, colourTo2_2, fixed3(angle2Norm_1,angle2Norm_1,angle2Norm_1)) + _AmbientColour1.xyz);
  o.xlv_TEXCOORD3 = tmpvar_12;



   
	return o;
	}


	fixed4 frag(VertexOutput i) : SV_Target
	
	
{
  float ShadowValue_1;
  half4 main_color_2;
  float x_3;
  x_3 = (dot (i.xlv_TEXCOORD3, _Plane0.xyz) - _Plane0.w);
  if ((x_3 < 0.0)) {
    discard;
  };
  float x_4;
  x_4 = (dot (i.xlv_TEXCOORD3, _Plane1.xyz) - _Plane1.w);
  if ((x_4 < 0.0)) {
    discard;
  };
  float x_5;
  x_5 = (dot (i.xlv_TEXCOORD3, _Plane2.xyz) - _Plane2.w);
  if ((x_5 < 0.0)) {
    discard;
  };
  float x_6;
  x_6 = (dot (i.xlv_TEXCOORD3, _Plane3.xyz) - _Plane3.w);
  if ((x_6 < 0.0)) {
    discard;
  };
  float x_7;
  x_7 = (dot (i.xlv_TEXCOORD3, _Plane4.xyz) - _Plane4.w);
  if ((x_7 < 0.0)) {
    discard;
  };
  float x_8;
  x_8 = (dot (i.xlv_TEXCOORD3, _Plane5.xyz) - _Plane5.w);
  if ((x_8 < 0.0)) {
    discard;
  };
  main_color_2 = fixed4(0.0, 0.0, 0.0, 0.0);
  fixed3 tmpvar_9;
  tmpvar_9 = (2.0 * UNITY_SAMPLE_TEX2D (unity_Lightmap, i.xlv_TEXCOORD1).xyz);
  ShadowValue_1 = clamp ((_ShadowRamp * (1.0 - tmpvar_9)).x, 0.001, 0.999);
  if ((_UseLightMap < 0.5)) {
    ShadowValue_1 = 0.0;
  };
  fixed4 tmpvar_10;
  tmpvar_10 = tex2D (_MainTex, i.uv);
  float3 tmpvar_11;
  tmpvar_11 = lerp (((_LightTint.xyz * i.xlv_TEXCOORD2) * tmpvar_10.xyz), _ShadowColour.xyz, fixed3(ShadowValue_1,ShadowValue_1,ShadowValue_1));
  main_color_2.xyz = tmpvar_11;
  main_color_2.w = 1.0;
   return main_color_2;
	}
	ENDCG
	}
  }
}

